﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using RAE.Logica.Info;
using RAE.Logica.Controladores;

namespace RAE.GUI.Inicio
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Autenticacion : Window
    {
        public Autenticacion()
        {
            Aplicacion.inicializar();
            InitializeComponent();
        }

        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            //Objects.Encryption service = new Objects.Encryption("ChessEncryptKey");
            
            Usuario usuario = obtenerUsuario();
            //String password = service.EncryptData(PassBox.Password);
            string password = text_password.Password;

            if (Aplicacion.autenticarUsuario(usuario, password))
            {
                Aplicacion.usuario_actual = usuario;
                new VentanaPrincipal().Show();
                this.Close();
            }
            else {
                label_errors.Content = "Usuario o contraseña no válidos.";
            }
        }

        private Usuario obtenerUsuario()
        {
            if (radio_encargado.IsChecked ?? false)
                return Usuario.ENCARGADO_ELO;
            else if (radio_admin.IsChecked ?? false)
                return Usuario.ADMINISTRADOR;
            else
                return Usuario.VISITA;
        }

        private void VisitanteClick(object sender, RoutedEventArgs e)
        {
            label_password.IsEnabled = false;
            text_password.Password = "";
            text_password.IsEnabled = false;

            label_errors.Content = "";
        }

        private void EncargadoClick(object sender, RoutedEventArgs e)
        {
            label_password.IsEnabled = true;
            text_password.Password = "";
            text_password.IsEnabled = true;

            label_errors.Content = "";
        }

        private void ContrasenaChange(object sender, RoutedEventArgs e)
        {
            label_errors.Content = "";
        }
    }
}
